from Base.Base import Base
from selenium.webdriver.common.by import By
from time import sleep
class Page_one(Base):
    # 点击登录
    to_login = (By.CLASS_NAME,'headerLogin')
    # 用户名输入框
    un=(By.ID,'userName')
    # 密码输入框
    pw=(By.ID,'password')

    # 点击登录
    login=(By.NAME,'bi_Usuallogin')
    # 点击确定
    sure=(By.CLASS_NAME,'bindSub')
    # 搜索框
    search=(By.ID,'wd')
    # 点击搜索
    search_btn=(By.CLASS_NAME,'search-btn')
    # 点击商品
    shop=(By.XPATH,'/html/body/div[6]/div/div[2]/div[5]/ul/li[1]/div[2]/div[1]/a/img')
    # 点击加入购物车
    add=(By.XPATH,'//*[@id="addToCartForDetail"]')

    # 登录成功断言
    login_su=(By.XPATH,'/html/body/div[2]/div/div[1]/div/p/span')



    def go_login(self):
        self.click(self.to_login)

    def send_un(self):
        self.send_leys(self.un,'15523670956')

    def send_pw(self):
        self.send_leys(self.pw,'Wzs123456')

    def click_login(self):
        self.click(self.login)

    def click_sure(self):
        self.click(self.sure)

    def get_dy(self):
        text=self.get_text(self.login_su)
        return text


    def search_sp(self):
        self.send_leys(self.search,'茅台')


    def search_click(self):
        self.click(self.search_btn)
    def click_sp(self):
        self.click(self.shop)

    def add_car(self):
        self.click(self.add)




    def test_one(self):
        self.go_login()
        self.send_un()
        self.send_pw()
        # 等待10秒输入验证码
        sleep(10)
        self.click_login()
        self.click_sure()
        text=self.get_dy()
        self.search_sp()
        self.search_click()
        self.click_sp()
        self.new_window()
        self.add_car()
        # 返回断言文本
        return text








